import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:get/get.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:media_scanner/media_scanner.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/Xwidgets/bottom_sheet.dart';
import 'package:yp/config/index.dart';
import 'package:yp/helper.dart';
import 'package:yp/router.dart';
import 'package:yp/services/api.dart';
import 'package:yp/utils/util.dart';
import 'package:yp/widgets/index.dart';

class InviteFriend extends StatefulWidget {
  const InviteFriend({Key key}) : super(key: key);

  @override
  _InviteFriendState createState() => _InviteFriendState();
}

class _InviteFriendState extends State<InviteFriend>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  String inviteCoupon; //我的奖励-优惠券
  String beInviteCoupon; // 好友奖励-优惠券
  Map inviteCouponMap = {};
  List inviteCouponList = [];
  Map beInviteCouponMap = {};
  List beInviteCouponList = [];
  String image, color;
  List inviFri = [];
  Map userInformationData = {};
  Map activity = {
    'invite_integral': null,
    'invite_growing': null,
    'invite_coupon': '',
    'be_invite_integral': null
  };
  int popMum = 0;
  GlobalKey repaintKey = GlobalKey();
  bool showTip = false;
  String shareUrlimg;

  getInviteData() {
    var params = {"ecactivity_id": 5};
    Api.activityfind(params).listen((event) {
      if (event['code'] == 0) {
        setState(() {
          activity = event['activity'];
          image = activity['slide_images'];
          color = activity['seckill_item_list'];
          if (event['activity']['invite_coupon'] != null) {
            // inviteCoupon = event['activity']['invite_coupon'].split(',')[0];
            inviteCoupon = event['activity']['invite_coupon'];
            getcoupon(inviteCoupon, 'inviteCoupon');
          }
          if (event['activity']['be_invite_coupon'] != null) {
            // beInviteCoupon =
            //     event['activity']['be_invite_coupon'].split(',')[0];
            beInviteCoupon =
            event['activity']['be_invite_coupon'];
            getcoupon(beInviteCoupon, 'beInviteCoupon');
          }
        });
      }
    });
  }

// 获取用户信息
  personInfo() {
    var params = {
      'access_token': SpUtil.getString('token'),
      'mobile': SpUtil.getString('number'),
    };
    Api.searchMember(params).listen((event) {
      if (event['code'] == 0) {
        userInformationData = event;
        shareUrlimg = Config.H5_URL +
            '&isGoInvitedFriend=true&from_usr_num_id=' +
            SpUtil.getInt('empeNumId').toString() +
            '&nick_name=' '+&logo=null';
      } else {
        userInformationData = {};
        shareUrlimg = Config.H5_URL +
            '&isGoInvitedFriend=true&from_usr_num_id=' +
            SpUtil.getInt('empeNumId').toString() +
            '&nick_name=' '&logo=null';
      }

      print('用户信息');
      print(userInformationData);
    });
  }

  getcoupon(id, type) {
    var params = {
      "sql_id": "SCRM_COUPONRULE_QUERY",
      "input_param": {"series": id}
    };
    print("gb.cexport.data.export ==:$params");
    Api.workCexport(params).listen((event) {
      print("++++++++$event");
      if (event['code'] == 0) {
        setState(() {
          if (type == 'inviteCoupon') {
            // inviteCouponMap = event['results'][0];
            inviteCouponList = event['results'];
          }
          if (type == 'beInviteCoupon') {
            // beInviteCouponMap = event['results'][0];
            beInviteCouponList = event['results'];
          }
        });
      }
    });

    var params2 = {
      "data_sign": 0,
      "channel_num_id": 99,
      "use_platform": 3,
      "sql_id": "SCRM-MEMBER-INVITATION",
      "input_param": {
        "from_usr_num_id": SpUtil.getInt('empeNumId'),
        "activity_id": 5
      }
    };
    Api.workCexport(params2).listen((event) {
      if (event['code'] == 0) {
        setState(() {
          if (event['results'] != null && event['results'].length > 0) {
            setState(() {
              popMum = event['results'].length;
              inviFri = event['results'];
            });
          }
        });
      }
    });
  }

  Future<Uint8List> capturePng() async {
    //检查是否有存储权限
    var status = await Permission.storage.status;
    if (!status.isGranted) {
      //如果客户拒绝过一次，则不再申请权限
      if (SpUtil.getBool('Permissionstoragestatus') == true) {
        toast('请在手机设置中授予存储访问权限');
        return null;
      }
      //未授权则发起一次申请
      status = await Permission.storage.request();
      print(status);
      return null;
    }

    BuildContext buildContext = repaintKey.currentContext;

    if (null != buildContext) {
      RenderRepaintBoundary boundary = buildContext.findRenderObject();
      ui.Image image = await boundary.toImage();
      ByteData byteData =
          await image.toByteData(format: ui.ImageByteFormat.png);
      final result =
          await ImageGallerySaver.saveImage(byteData.buffer.asUint8List());
      print(' $result');
      if (Platform.isAndroid && result["isSuccess"]) {
        MediaScanner.loadMedia(path: result["filePath"]);
      }
      toast('保存成功');
    }
  }

  @override
  void initState() {
    super.initState();
    getInviteData();
    personInfo();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // ScreenUtil.init(
    //     BoxConstraints(
    //         maxWidth: MediaQuery.of(context).size.width,
    //         maxHeight: MediaQuery.of(context).size.height),
    //     designSize: Size(750, 1334),
    //     orientation: Orientation.portrait);
    return Stack(
      children: [
        Scaffold(
          appBar: YPNavigationBar(
            '邀请好友有礼',
            showBack: !kIsWeb,
          ),
          // floatingActionButton: GestureDetector(
          //   onTap: () {
          //     Get.offAllNamed(RouteConfig.main);
          //   },
          //   child: Container(
          //     width: 50,
          //     height: 50,
          //     decoration: BoxDecoration(
          //       color: Color(0xfff84034),
          //       borderRadius: BorderRadius.circular(25),
          //     ),
          //     child: Icon(Icons.home, color: Colors.white),
          //   ),
          // ),
          body: CustomScrollView(
            slivers: [
              SliverToBoxAdapter(
                  child: Column(
                children: [
                  if (image != null)
                    Image.network(
                      // 'assets/images/invite_friend_head.png',
                      image,
                      width: double.infinity,
                      height: MediaQuery.of(context).size.width / 1.36,
                      fit: BoxFit.fill,
                    ),
                  SizedBox(height: 10),
                  _invite(),
                  _inviteInfo()
                ],
              ))
            ],
          ),
          backgroundColor:
              color == null ? Color(0xfffe8937) : getColorFromHex(color),
        ),
        if (showTip)
          Container(
            color: Colors.black45.withOpacity(.75),
            child: Center(
                child: Text(
              "请点击右上角的'...'\n然后选择在浏览器打开",
              style: TextStyle(
                color: Colors.white,
                fontSize: 18,
              ),
              textAlign: TextAlign.center,
            )),
          ),
      ],
    );
  }

  /// 第一个卡片
  Widget _invite() {
    return Container(
      margin: EdgeInsets.fromLTRB(24.w, 0, 24.w, 24.w),
      padding: EdgeInsets.all(36.w),
      width: double.infinity,
      decoration: BoxDecoration(
          color: EsColors.White, borderRadius: BorderRadius.circular(20.w)),
      child: Column(
        children: [
          Row(
            children: [
              Expanded(
                  child: Container(
                      color: Color(0xffb74900).withOpacity(0.2), height: 1.w)),
              SizedBox(width: 24.w),
              Text(
                '我的奖励',
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                    color: EsColors.MoneySecondary,
                    fontSize: EsSizes.LG * 2.sp,
                    fontWeight: EsFontWeights.SemiBold),
              ),
              SizedBox(width: 24.w),
              Expanded(
                  child: Container(
                      color: Color(0xffb74900).withOpacity(0.2), height: 1.w))
            ],
          ),
          ListView.builder(
            itemCount: inviteCouponList.isNotEmpty ? inviteCouponList.length : 0,
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              var item = inviteCouponList[index];
              return item["face_value"] != null
                  ? Container(
                      width: double.infinity,
                      height: 200.w,
                      margin: EdgeInsets.only(top: 36.w, bottom: 20.w),
                      child: Row(children: [
                        Expanded(
                          // flex: 1,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              RichText(
                                  maxLines: 1,
                                  textAlign: TextAlign.center,
                                  text: TextSpan(children: [
                                    TextSpan(
                                        text: '￥',
                                        style: TextStyle(
                                            fontSize: EsSizes.LG * 2.sp,
                                            fontWeight: EsFontWeights.SemiBold,
                                            color: EsColors.White)),
                                    TextSpan(
                                        text: item['face_value']
                                            .toString()
                                            .replaceAll(".0", ""),
                                        style: TextStyle(
                                            fontSize: 25 * 2.sp,
                                            fontWeight: EsFontWeights.SemiBold,
                                            color: EsColors.White))
                                  ])),
                              // Container(
                              //   padding: EdgeInsets.symmetric(vertical: 0, horizontal: 20.w),
                              //   decoration: BoxDecoration(color: Color(0xffd32f14), borderRadius: BorderRadius.circular(16.w)),
                              //   child: Text(
                              //     '满49可用',
                              //     maxLines: 1,
                              //     overflow: TextOverflow.ellipsis,
                              //     style: TextStyle(color: EsColors.White, fontSize: EsSizes.XS * 2.sp, fontWeight: EsFontWeights.Normal),
                              //   ),
                              // )
                            ],
                          ),
                        ),
                        Expanded(
                            // flex: 2,
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Text(
                                  item['title'] != null
                                      ? item['title']
                                      : '',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                      color: EsColors.MoneySecondary,
                                      fontSize: EsSizes.MD * 2.sp,
                                      fontWeight: EsFontWeights.SemiBold),
                                ),
                                SizedBox(height: 14),
                                Text(
                                  item['discount_description'] !=
                                          null
                                      ? item['discount_description']
                                      : 'app，小程序专享',
                                  style: TextStyle(
                                      color: Color(0XFFA64F00),
                                      fontSize: EsSizes.XS * 2.sp,
                                      fontWeight: EsFontWeights.Normal),
                                ),
                              ],
                            ))
                      ]),
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              fit: BoxFit.fill,
                              image: AssetImage(
                                  'assets/images/give_coupons_bg.png'))),
                    )
                  : Row(children: [
                      if (activity['invite_integral'] != null)
                        Expanded(
                          child: Container(
                            padding:
                                EdgeInsets.fromLTRB(24.w, 32.w, 12.w, 32.w),
                            decoration: BoxDecoration(
                                color: Color(0xffea5504).withOpacity(0.05),
                                borderRadius: BorderRadius.circular(20.w)),
                            child: Row(children: [
                              Image.asset(
                                'assets/images/integral_val.png',
                                width: 52.w,
                                height: 58.w,
                                fit: BoxFit.fill,
                              ),
                              SizedBox(width: 24.w),
                              Expanded(
                                child: RichText(
                                    textAlign: TextAlign.left,
                                    text: TextSpan(children: [
                                      TextSpan(
                                          text:
                                              '+${activity['invite_integral']}',
                                          style: TextStyle(
                                              color: EsColors.Primary,
                                              fontWeight: EsFontWeights.Medium,
                                              fontSize: EsSizes.LG * 2.sp)),
                                      TextSpan(
                                          text: ' 积分',
                                          style: TextStyle(
                                              color: EsColors.Content,
                                              fontWeight: EsFontWeights.Medium,
                                              fontSize: EsSizes.XS * 2.sp))
                                    ])),
                              )
                            ]),
                          ),
                        ),
                      SizedBox(width: 16.w),
                      if (activity['invite_growing'] != null)
                        Expanded(
                          child: Container(
                            padding:
                                EdgeInsets.fromLTRB(24.w, 32.w, 12.w, 32.w),
                            decoration: BoxDecoration(
                                color: Color(0xffea5504).withOpacity(0.05),
                                borderRadius: BorderRadius.circular(20.w)),
                            child: Row(children: [
                              Image.asset(
                                'assets/images/growth_value.png',
                                width: 48.w,
                                height: 48.w,
                                fit: BoxFit.fill,
                              ),
                              SizedBox(width: 24.w),
                              Expanded(
                                child: RichText(
                                    textAlign: TextAlign.left,
                                    text: TextSpan(children: [
                                      TextSpan(
                                          text:
                                              '+${activity['invite_growing']}',
                                          style: TextStyle(
                                              color: EsColors.Primary,
                                              fontWeight: EsFontWeights.Medium,
                                              fontSize: EsSizes.LG * 2.sp)),
                                      TextSpan(
                                          text: ' 成长值',
                                          style: TextStyle(
                                              color: EsColors.Content,
                                              fontWeight: EsFontWeights.Medium,
                                              fontSize: EsSizes.XS * 2.sp))
                                    ])),
                              )
                            ]),
                          ),
                        )
                    ]);
            },
          ),
          SizedBox(height: 40.w),
          Row(
            children: [
              Expanded(
                  child: Container(
                      color: Color(0xffb74900).withOpacity(0.2), height: 1.w)),
              SizedBox(width: 24.w),
              Text(
                '好友奖励',
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                    color: EsColors.MoneySecondary,
                    fontSize: EsSizes.LG * 2.sp,
                    fontWeight: EsFontWeights.SemiBold),
              ),
              SizedBox(width: 24.w),
              Expanded(
                  child: Container(
                      color: Color(0xffb74900).withOpacity(0.2), height: 1.w))
            ],
          ),
          ListView.builder(
              itemCount: beInviteCouponList.isNotEmpty ? beInviteCouponList
                  .length : 0,
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (context, index) {
                var item = beInviteCouponList[index];
                return item['face_value'] != null ?
                Visibility(
                  visible: beInviteCouponList != null,
                  child: Container(
                    width: double.infinity,
                    height: 200.w,
                    margin: EdgeInsets.only(top: 36.w, bottom: 20.w),
                    child: Row(children: [
                      Expanded(
                        flex: 1,
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            RichText(
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                textAlign: TextAlign.center,
                                text: TextSpan(children: [
                                  TextSpan(
                                      text: '￥',
                                      style: TextStyle(
                                          fontSize: EsSizes.LG * 2.sp,
                                          fontWeight: EsFontWeights.SemiBold,
                                          color: EsColors.White)),
                                  TextSpan(
                                      text: item['face_value']
                                          .toString()
                                          .replaceAll(".0", ""),
                                      style: TextStyle(
                                          fontSize: 25 * 2.sp,
                                          fontWeight: EsFontWeights.SemiBold,
                                          color: EsColors.White))
                                ])),
                          ],
                        ),
                      ),
                      Expanded(
                          flex: 2,
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Text(
                                item['title'] != null
                                    ? item['title'].toString()
                                    : '',
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    color: EsColors.White,
                                    fontSize: EsSizes.MD * 2.sp,
                                    fontWeight: EsFontWeights.SemiBold),
                              ),
                              SizedBox(height: 14),
                              Text(
                                item['discount_description'] !=
                                    null
                                    ? item['discount_description']
                                    : 'app，小程序专享',
                                style: TextStyle(
                                    color: EsColors.White,
                                    fontSize: EsSizes.XS * 2.sp,
                                    fontWeight: EsFontWeights.Normal),
                              ),
                            ],
                          ))
                    ]),
                    decoration: BoxDecoration(
                        image: DecorationImage(
                            fit: BoxFit.fill,
                            image:
                            AssetImage('assets/images/give_coupons_bg_1.png'))),
                  ),
                ) :
                Row(children: [
                  if (activity['be_invite_integral'] != null)
                    Expanded(
                      child: Container(
                        padding: EdgeInsets.fromLTRB(24.w, 32.w, 12.w, 32.w),
                        decoration: BoxDecoration(
                            color: Color(0xffea5504).withOpacity(0.05),
                            borderRadius: BorderRadius.circular(20.w)),
                        child: Row(children: [
                          Image.asset(
                            'assets/images/integral_val.png',
                            width: 52.w,
                            height: 58.w,
                            fit: BoxFit.fill,
                          ),
                          SizedBox(width: 24.w),
                          Expanded(
                            child: RichText(
                                textAlign: TextAlign.left,
                                text: TextSpan(children: [
                                  TextSpan(
                                      text: '+${activity['be_invite_integral']}',
                                      style: TextStyle(
                                          color: EsColors.Primary,
                                          fontWeight: EsFontWeights.Medium,
                                          fontSize: EsSizes.LG * 2.sp)),
                                  TextSpan(
                                      text: ' 积分',
                                      style: TextStyle(
                                          color: EsColors.Content,
                                          fontWeight: EsFontWeights.Medium,
                                          fontSize: EsSizes.XS * 2.sp))
                                ])),
                          )
                        ]),
                      ),
                    ),
                  SizedBox(width: 16.w),
                  if (activity['be_invite_growing'] != null)
                    Expanded(
                      child: Container(
                        padding: EdgeInsets.fromLTRB(24.w, 32.w, 12.w, 32.w),
                        decoration: BoxDecoration(
                            color: Color(0xffea5504).withOpacity(0.05),
                            borderRadius: BorderRadius.circular(20.w)),
                        child: Row(children: [
                          Image.asset(
                            'assets/images/growth_value.png',
                            width: 48.w,
                            height: 48.w,
                            fit: BoxFit.fill,
                          ),
                          SizedBox(width: 24.w),
                          Expanded(
                            child: RichText(
                                textAlign: TextAlign.left,
                                text: TextSpan(children: [
                                  TextSpan(
                                      text: '+${activity['be_invite_growing']}',
                                      style: TextStyle(
                                          color: EsColors.Primary,
                                          fontWeight: EsFontWeights.Medium,
                                          fontSize: EsSizes.LG * 2.sp)),
                                  TextSpan(
                                      text: ' 成长值',
                                      style: TextStyle(
                                          color: EsColors.Content,
                                          fontWeight: EsFontWeights.Medium,
                                          fontSize: EsSizes.XS * 2.sp))
                                ])),
                          )
                        ]),
                      ),
                    )
                ]);
              }),
          SizedBox(height: 36.w),
          SizedBox(
            width: double.infinity,
            height: 60.w,
            child: Swiper(
              itemBuilder: (BuildContext context, int index) {
                //条目构建函数传入了index,根据index索引到特定图片
                return Container(
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: Color(0xfffbf2dc),
                        borderRadius: BorderRadius.circular(26.w)),
                    child: Text('136****5342成功邀请5人，获得了5元优惠券',
                        style: TextStyle(
                            color: EsColors.MoneySecondary,
                            fontSize: EsSizes.XS * 2.sp,
                            fontWeight: EsFontWeights.Normal)));
              },
              itemCount: 3,
              autoplay: true,
              scrollDirection: Axis.vertical,
            ),
          ),
          SizedBox(height: 32.w),
          IconButton(
              onPressed: () {
                if (kIsWeb) {
                  Future.delayed(Duration(seconds: 1), () {
                    if (isWechat()) {
                      // toast('请在系统浏览器打开本页面');
                      setState(() {
                        showTip = true;
                      });
                    } else {
                      /// 进入下载页
                      webpay("${Config.WEB_DOWN_URL}download.html");
                    }
                  });
                  webpay("yinpinhui://zrhsh.com/app?invite_friend=1");
                } else {
                  YpBottomSheet.showShareGift(context,
                      (selectIndex, selectString, {info, list}) {
                    var shareUrl;
                    // shareUrl =   Config.WEB_URL +
                    //     'collect_coupons?usr_num_id=' +
                    //     SpUtil.getInt('empeNumId').toString() +
                    //     "&series=${beInviteCouponMap['series']}"
                    shareUrl = Config.H5_URL +
                        '&isGoInvitedFriend=true&from_usr_num_id=' +
                        SpUtil.getInt('empeNumId').toString() +
                        '&nick_name=' '&logo=' +
                        userInformationData['logo'];

                    if (selectIndex == 0) {
                      var model = fluwx.WeChatShareWebPageModel(
                        shareUrl,
                        description: activity['ecactivity_desc'],
                        title: activity['share_desc'],
                        thumbnail:
                            fluwx.WeChatImage.network(activity['share_images']),
                        scene: fluwx.WeChatScene.SESSION,
                      );
                      fluwx.shareToWeChat(model);
                    } else {
                      var model = fluwx.WeChatShareWebPageModel(
                        shareUrl,
                        description: activity['ecactivity_desc'],
                        title: activity['share_desc'],
                        thumbnail:
                            fluwx.WeChatImage.network(activity['share_images']),
                        scene: fluwx.WeChatScene.TIMELINE,
                      );
                      fluwx.shareToWeChat(model);
                    }
                  });
                }

                // var model = new WeChatShareMiniProgramModel(
                //              path: '/pages/index,
                //              webPageUrl: 'www.baidu.com',
                //              userName: Config.MINI_ACCOUNT,
                //              // mini  ProgramType: WXMiniProgramType.RELEASE,
                //              miniProgramType: WXMiniProgramType.RELEASE,
                //              title: item.itemName,
                //              description: item.itemName,
                //              thumbnail: WeChatImage.network(
                //                "${item.imageSrc}",
                //              ),
                //            );
                //            fluwx.shareToWeChat(model);
                print('立即邀请');
              },
              icon: Image.asset('assets/images/invite_btn.png',
                  width: double.infinity, height: 104.w, fit: BoxFit.fill),
              padding: EdgeInsets.zero,
              constraints:
                  BoxConstraints(minHeight: 104.w, minWidth: double.infinity)),
          SizedBox(height: 36.w),
          TextButton(
              onPressed: () {
                print('面对面邀请');

                if (kIsWeb) {
                  Future.delayed(Duration(seconds: 1), () {
                    if (isWechat()) {
                      // toast('请在系统浏览器打开本页面');
                      setState(() {
                        showTip = true;
                      });
                    } else {
                      /// 进入下载页
                      webpay("https://nrp3mall-uat.zrhsh.com/download.html");
                    }
                  });
                  webpay("yinpinhui://zrhsh.com/app");
                } else {
                  showDialog(
                    // 传入 context
                    context: context,
                    // 构建 Dialog 的视图
                    builder: (_) => Padding(
                      padding: EdgeInsets.all(16),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: <Widget>[
                          Container(
                            alignment: Alignment.center,
                            color: Colors.white,
                            child: Column(
                              children: <Widget>[
                                RepaintBoundary(
                                  key: repaintKey,
                                  child: QrImage(
                                    backgroundColor: Colors.white70,
                                    data: shareUrlimg,
                                    version: QrVersions.auto,
                                    size: 200.0,
                                  ),
                                ),
                                Padding(
                                  padding: EdgeInsets.only(top: 8),
                                  child: GestureDetector(
                                    onTap: () {
                                      var data = Config.WEB_URL +
                                          'collect_coupons?usr_num_id=' +
                                          SpUtil.getInt('empeNumId')
                                              .toString() +
                                          "&series=${beInviteCouponMap['series']}";
                                      print("datadatadatadatadata=$data");

                                      Get.toNamed(RouteConfig.collectCoupons,
                                          arguments: {
                                            "usr_num_id":
                                                SpUtil.getInt('empeNumId')
                                                    .toString(),
                                            "series":
                                                beInviteCouponMap['series'],
                                          });
                                    },
                                    child: Text('让朋友扫一扫上面的二维码',
                                        style: TextStyle(
                                            fontSize: 32.w,
                                            decoration: TextDecoration.none)),
                                  ),
                                ),
                                Padding(
                                    padding: EdgeInsets.all(10.0),
                                    child: MaterialButton(
                                      color: Colors.orange,
                                      textColor: Colors.white,
                                      child: new Text('点我截图'),
                                      onPressed: () {
                                        // ...
                                        capturePng();
                                      },
                                    )),
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  );
                }
              },
              style: OutlinedButton.styleFrom(
                // 去除放大点击区域
                tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                minimumSize: Size(0, 0),
                padding: EdgeInsets.zero,
                primary: EsColors.White,
              ),
              child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset('assets/images/code_tips.png',
                        width: 40.w, height: 40.w, fit: BoxFit.fill),
                    SizedBox(width: 14.w),
                    Text(
                      '面对面邀请',
                      style: TextStyle(
                          color: EsColors.MoneySecondary,
                          fontSize: EsSizes.SM * 2.sp,
                          fontWeight: EsFontWeights.Normal),
                    )
                  ]))
        ],
      ),
    );
  }

  /// 第二个卡片
  Widget _inviteInfo() {
    return Container(
      margin: EdgeInsets.fromLTRB(24.w, 0, 24.w, 80.w),
      padding: EdgeInsets.all(36.w),
      width: double.infinity,
      decoration: BoxDecoration(
          color: EsColors.White, borderRadius: BorderRadius.circular(10)),
      child: Column(
        children: [
          Row(
            children: [
              Expanded(
                  child: Container(
                      color: Color(0xffd8d8d8).withOpacity(0.2), height: 1.w)),
              SizedBox(width: 24.w),
              Text(
                '已邀请人数($popMum人)',
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                    color: EsColors.Title,
                    fontSize: EsSizes.SM * 2.sp,
                    fontWeight: EsFontWeights.Medium),
              ),
              SizedBox(width: 24.w),
              Expanded(
                  child: Container(
                      color: Color(0xffd8d8d8).withOpacity(0.2), height: 1.w))
            ],
          ),
          popMum <= 0
              ? SizedBox(
                  height: 260.w,
                  width: double.infinity,
                  child: Center(
                    child: Text(
                      '暂无奖励，赶快去邀请好友吧～',
                      style: TextStyle(
                          color: EsColors.Content,
                          fontSize: EsSizes.SM * 2.sp,
                          fontWeight: EsFontWeights.Normal),
                    ),
                  ))
              : Container(
                  height: 400.w,
                  child: ListView.builder(
                    // scrollDirection: Axis.horizontal,//设置为水平布局
                    itemBuilder: (BuildContext context, int index) {
                      return Text(
                        inviFri[index]['mobile_phone']
                            .toString()
                            .replaceFirst(new RegExp(r'\d{4}'), '****', 3),
                        style: TextStyle(color: Colors.black),
                      );
                    },
                    itemCount: inviFri.length,
                  ),
                )
        ],
      ),
    );
  }
}
